package fr.noe.amicaleloisirs.concours.utils;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;

/**
 * API FileSystem
 *
 * @author Sébastien PREVOST
 *
 */
public class FileSystem {

	private static FileSystem impl = null;

	public static FileSystem get() {
		if (impl == null)
			impl = new FileSystem();
		return impl;
	}

	public final Element getAppletElement() {
		return Document.get().getElementById(Constants.FILE_APPLET_ID);
	}

	public final native boolean fileDelete(String file) /*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.fileDelete(file);
	}-*/;

	public final native boolean dirCreate(String dirname) /*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.dirCreate(dirname);
	}-*/;

	public final native boolean dirDelete(String dirname) /*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.dirDelete(dirname);
	}-*/;

	public final native boolean dirExists(String dirname) /*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.dirExists(dirname);
	}-*/;

	public final native boolean fileExists(String filename) /*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.fileExists(filename);
	}-*/;

	public final native boolean copy(String srcfilename, String dstfilename) /*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.copy(srcfilename,dstfilename);
	}-*/;

	public final native boolean move(String srcfilename, String dstfilename)	/*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.move(srcfilename,dstfilename);
	}-*/;

	public final native String read(String filename) /*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.read(filename);
	}-*/;

	public final native String read() /*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.read();
	}-*/;

	public final native boolean write(String filename, String content) /*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.write(filename,content);
	}-*/;

	public final native boolean append(String filename, String content) /*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.append(filename,content);
	}-*/;

	public final native String[] dirList(String dirname)	/*-{
		var obj = this;
		var applet = obj.@fr.noe.amicaleloisirs.concours.utils.FileSystem::getAppletElement()();
		return applet.append(dirname);
	}-*/;

}
